<template>
  归类文件至
  <Select v-model="tid" style="width:200px">
    <Option v-for="item in fileTypeDatum" :value="item.id" :key="item.id">{{ item.name }}</Option>
  </Select>
</template>

<script setup>

import {getCurrentInstance, onMounted, ref} from "vue";
import {Option, Select} from "view-ui-plus";
import {FileService} from "@/api/file";

const tid = ref(0)

const fileTypeDatum = ref([])

const ids = ref([]);

const {proxy} = getCurrentInstance();

const classifyFile = async () => {
  const param = {
    ids: ids.value,
    tid: tid.value
  };
  if (ids.value.length === 0) {
    proxy.$Message.warning({
      content: '请至少选择一项',
      duration: 1.5,
      onClose: () => {
        window.location.reload();
      }
    })
  } else {
    await postClassify(param);
  }
}

const postClassify = async (param) => {
  const {data} = await FileService.ClassifyFiles(param);
  if (data.code === 200) {
    proxy.$Message.success({
      content: data.data,
      duration: 1.5,
      onClose: () => {
        // CommonServices.getMenus();
        window.location.reload()
      }
    })
  } else {
    proxy.$Message.error({
      content: data.data,
      duration: 1.5,
      onClose: () => {
        Promise.reject()
      }
    })
  }
}

onMounted(() => {
})

defineExpose({
  tid,
  fileTypeDatum,
  classifyFile,
  ids
})

</script>

<style scoped>

</style>
